<?php
namespace app\common\wx;

use app\common\httpdown\HttpRequest;
use app\common\wx\Token;

class Custom{        
    /**
    * 获取微信客服消息
    */
    public function send($originalid,$data){
        $token =  new Token();
        $url = 'https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token='.$token->getAccessToken($originalid);
        $http = new HttpRequest();
        $resuthtml = $http->https_request($url,toJson($data));
    }

    /**
    * 对数据进行转码，避免中文转json时乱码
    * @param array & string $data
    */
    public function toJson($data) {
        $data = json_encode($this->urlencodeAry($data));
        return urldecode($data);
    }

    /**
    * 将数据进行urlencode
    * @param array & string $data
    */
    public function urlencodeAry($data) {
        if(is_array($data)) {
            foreach($data as $key=>$val) {
                $data[$key] = $this->urlencodeAry($val);
            }
            return $data;
        } else {
            return urlencode($data);
        }
    }
}